﻿#pragma once

#include <E_City.nanopb.h>
#include <DescStore/CityMapDesc.h>

#include "proto_common_map.nanopb.h"
#include "NFServerComm/NFServerCommon/NFIDescStoreEx.h"
#include "NFServerComm/NFServerCommon/NFIDescTemplate.h"
#include "NFComm/NFObjCommon/NFShmMgr.h"
#include "NFComm/NFShmStl/NFShmHashMap.h"
#include "NFLogicCommon/NFDescStoreTypeDefines.h"

const int DEFAULT_MAP_GRID_SIZE = 150000;
const int MAX_MAP_GRID_NUM = 600;

const int DEFAULT_MAP_SIZE_GAP = 15000;
const int MAX_GUILD_STATION_MAP_GRID_NUM = 36;

class CCityMapData
{
public:
	CCityMapData()
	{
		if (EN_OBJ_MODE_INIT == NFShmMgr::Instance()->GetCreateMode())
		{
			CreateInit();
		}
		else
		{
			ResumeInit();
		}
	}

	~CCityMapData()
	{
	}

	int CreateInit();
	int ResumeInit();
	int LoadMapData(E_CityMap* pstCityMapDesc);

	int GetGridSize() const { return m_iGridSize; }
	int GetXGridNum() const { return m_iXGridNum; }
	int GetZGridNum() const { return m_iZGridNum; }
	const MapDataDesc* GetMapData() const { return &m_stMapData; }

	bool IsPositionValid(Proto_Vector3& stPos) const;

private:
	int CalcMapGrid();

private:
	int m_iMapID;
	MapDataDesc m_stMapData;
	int m_iXGridNum;
	int m_iZGridNum;
	int m_iGridSize;
};

class CityDescEx : public NF_OBJECT_GLOBAL_TEMPLATE_MACRO(CityDescEx, EOT_CONST_CITY_DESC_EX_ID, NFIDescStoreEx)
public:
	CityDescEx();
	virtual ~CityDescEx();
	int CreateInit();
	int ResumeInit();

public:
	virtual int Load() override;
	virtual int CheckWhenAllDataLoaded() override;

public:
	const CCityMapData* GetCityMapData(int iMapId) const;

private:
	NFShmHashMap<int, CCityMapData, MAX_CITY_MAP_NUM> m_aCityMapData;
};
